<?php

namespace StudyBuddy;

/**
 * StudyBuddyObserver is basically the same as SplObserver
 * except that it requires to have a constructor
 * that accepts Registry object
 *
 * This way all StudyBuddy\Observer classes are guaranteed to have
 * access to Registry
 *
 */
class Observer implements \SplObserver {

    protected $oRegistry;
    protected $obj;
    protected $aInfo;
    protected $eventName;

    public function __construct(Registry $oRegistry) {
        d('observer: ' . get_class($this));
        $this->oRegistry = $oRegistry;
    }

    /**
     * Factory method.
     * All Observers are instantiated via
     * a factory method.
     * This way an observer may have own
     * factory method and have a login inside it
     * to return instance of different class depending
     * on some conditions. This extra abstruction
     * makes writing custom Observer even
     * more flexible
     * 
     * 
     * @param Registry $oRegistry
     */
    public static function factory(Registry $oRegistry) {
        return new static($oRegistry);
    }

    /**
     * Implementation of
     * SplSubject::update method
     * 
     * (non-PHPdoc)
     * @see SplObserver::update()
     */
    public function update(\SplSubject $oNotification) {

        $this->eventName = $oNotification->getNotificationName();
        $this->obj = $oNotification->getNotificationObject();
        $this->aInfo = $oNotification->getNotificationInfo();

        $this->main();
    }

    protected function main() {
        
    }

}

